package com.yzpc.service.Impl;

import com.yzpc.entity.MouseClick;
import com.yzpc.entity.Script;
import com.yzpc.mapper.MouseClickMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MouseClickService {

    @Autowired
    private MouseClickMapper mouseClickMapper;

    public int saveClick(MouseClick mouseClick) {
        return mouseClickMapper.insertMouseClick(mouseClick);
    }

    public List<MouseClick> getMouseClicks() {
        // 查找 used 为 1 的脚本
        Script script = mouseClickMapper.findUsedScript();
        if (script != null) {
            // 更新脚本状态将 used 设置为 0
            mouseClickMapper.setScriptUsedToZero(script.getScriptId());
            // 根据被使用的脚本 ID 获取鼠标点击记录
            List<MouseClick> scripts = mouseClickMapper.findMouseClicksByScriptId(script.getScriptId());
            System.out.println(scripts);
            return scripts;
        }
        return null; // 如果没有找到可用的脚本
    }
}